﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2010 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * This page shows all resources available in a folder in the File Browser.
-->
<html>
<head>
	<title>Resources</title>
	<link href="browser.css" type="text/css" rel="stylesheet">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<script type="text/javascript" src="js/common.js"></script>

     <script type="text/javascript">


         var oListManager = new Object();

         oListManager.Clear = function () {
             document.body.innerHTML = '';
         }

         function ProtectPath(path) {
             path = path.replace(/\\/g, '\\\\');
             path = path.replace(/'/g, '\\\'');
             return path;
         }


         oListManager.GetFolderRowHtml = function (folderName, folderPath) {
             // Build the link to view the folder.
             var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath(folderPath) + '\');return false;">';


             return '<tr>' +
   '<td width="16">' +
    sLink +
    '<img alt="" src="images/Folder.gif" width="16" height="16" border="0"><\/a>' +
   '<\/td><td nowrap colspan="2">&nbsp;' +
    sLink +
    folderName +
    '<\/a>' +
		'<a href="#" onclick="delFolder(\'' + ProtectPath(folderName) + '\')">删除<\/a><\/td><\/tr>';
         }

         oListManager.GetFileRowHtml = function (fileName, fileUrl, fileSize) {
             // Build the link to view the folder.
             //var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;">' ;
             var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath(fileUrl) + '\');return false;"><div style="padding:10px 30px 30px 30px; float:left;"><img src="' + fileUrl + '" width="100px" height="100px" class=GetFoldersAndFilesCallBack "huangxu" border="0" /><span style="margin-left:-100px;margin-top:110px;position: absolute;width:50px;height:50px;">' + fileName + '</span><a href="#" mce_href="#" onclick="deleteFile(\'' + ProtectPath(fileUrl) + '\');" style="margin-left:-18px;"> <img src="images/delete.gif" width="16px" height="16px" border="0"/><\/a></div>'; //这里设置显示的值



             // Get the file icon.
             var sIcon = oIcons.GetIcon(fileName);   
  
             return sLink + '<\/a>';
         }

         function OpenFolder(folderPath) {
             // Load the resources list for this folder.
             window.parent.frames['frmFolders'].LoadFolders(folderPath);
         }

         function OpenFile(fileUrl) {
             window.top.parent.SetUrl(escape(fileUrl));
             window.top.close();
             window.top.parent.focus();
         }

         function LoadResources(resourceType, folderPath) {
             oListManager.Clear();
             oConnector.ResourceType = resourceType;
             oConnector.CurrentFolder = folderPath;
             oConnector.SendCommand('GetFoldersAndFiles', null, GetFoldersAndFilesCallBack);

         }

         function Refresh() {
             LoadResources(oConnector.ResourceType, oConnector.CurrentFolder);
         }


         function GetFoldersAndFilesCallBack(fckXml) {
             if (oConnector.CheckError(fckXml) != 0)
                 return;


             // Get the current folder path.
             var oFolderNode = fckXml.SelectSingleNode('Connector/CurrentFolder');
             if (oFolderNode == null) {
                 alert('The server didn\'t reply with a proper XML data. Please check your configuration.');
                 return;
             }
             var sCurrentFolderPath = oFolderNode.attributes.getNamedItem('path').value;
             var sCurrentFolderUrl = oFolderNode.attributes.getNamedItem('url').value;

             // var dTimer = new Date() ;


             //var oHtml = new StringBuilder( '<table id="tableFiles" cellspacing="1" cellpadding="0" width="100%" border="1">' ) ;
             var oHtml = new StringBuilder('<div id="tableFiles" width="100%" border="1">');


             // Add the Folders.
             var oNodes;
             oNodes = fckXml.SelectNodes('Connector/Folders/Folder');
             for (var i = 0; i < oNodes.length; i++) {
                 var sFolderName = oNodes[i].attributes.getNamedItem('name').value;
                 oHtml.Append(oListManager.GetFolderRowHtml(sFolderName, sCurrentFolderPath + sFolderName + "/"));
             }

             // Add the Files.
             oNodes = fckXml.SelectNodes('Connector/Files/File');
             for (var j = 0; j < oNodes.length; j++) {
                 var oNode = oNodes[j];
                 var sFileName = oNode.attributes.getNamedItem('name').value;
                 var sFileSize = oNode.attributes.getNamedItem('size').value;


                 // Get the optional "url" attribute. If not available, build the url.
                 var oFileUrlAtt = oNodes[j].attributes.getNamedItem('url');
                 var sFileUrl = oFileUrlAtt != null ? oFileUrlAtt.value : encodeURI(sCurrentFolderUrl + sFileName).replace(/#/g, '%23');


                 oHtml.Append(oListManager.GetFileRowHtml(sFileName, sFileUrl, sFileSize));
             }

             oHtml.Append('<\/div>');

             document.body.innerHTML = oHtml.ToString();

             // window.top.document.title = 'Finished processing in ' + ( ( ( new Date() ) - dTimer ) / 1000 ) + ' seconds' ;

         }


         window.onload = function () {
             window.top.IsLoadedResourcesList = true;
         }
         /*-----------------实现文件文件删除功能---------------------------------*/
         //产生不重复的随机数
         var rn = Math.ceil(Math.random() * 1000000);
         var rnch = rn;
         function rndnum() {
             while (rn == rnch) rn = Math.ceil(Math.random() * 1000000);
             rnch = rn;
             return rn;
         }
         // 删除文件
         function deleteFile(file) {
             var xml = new ActiveXObject("MSXML2.XMLHTTP");
             xml.open("get", "FCKdel_file.aspx?filePath=" + escape(file) + "&UD=" + rndnum()+"&type=1", false);
             xml.send();
             Refresh();
             switch (xml.responseText) {
                 case "1": alert("文件删除成功!");
                     break;
                 case "0": alert("文件删除失败!请检查文件是否存在!");
                     break;
             }
         }

         function delFolder(Folder) {
             alert(Folder);
             var xml = new ActiveXObject("MSXML2.XMLHTTP");
             xml.open("get", "FCKdel_file.aspx?filePath=" + escape(Folder) + "&UD=" + rndnum() + "&type=0", false);
             xml.send();
             Refresh();
         }
 </script>
 <script runat="server">
 
 </script>
</head>
<body class="FileArea">
<div id="showFile" style="float:left;display:none;background-color:#999999"></div>
<iframe id="iframe_del" name="iframe_del" width="0" height="0" scrolling="no"></iframe>
<div id="body_content"></div>
</body>
</html>
